<?php

namespace app\api\library;


use app\api\controller\Validate;
use think\exception\Handle;

class Wiamp extends Handle
{
    private static $pid = 'wntest';
    private static $pwd = '135246';
    private static $BaseUrl = 'http://testwx.jifenfu.net/orderCard2!order.do';
    private static $BatchNo_SYNC = '201807100670';
    private static $BatchNo_ASYNCH = '201701174378';

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 生成签名字符串
     */
    public static function getSign($param)
    {
        //签名步骤一：对于所有参数及对应值utf-8编码的URLEncode
        $string = self::ToUrlParams($param);
        // var_dump($string);
        //签名步骤二：进行32位算法的MD5加密
        $string = md5($string, FALSE);
        //  var_dump($string);
        //签名步骤三：所有字符转为小写
        $result = strtolower($string);
        //var_dump($result);
        return $result;
    }

    /**
     * 格式化参数格式化成url参数
     */
    public static function ToUrlParams($param)
    {
        $buff = "";
        foreach ($param as $k => $v) {
            if ($k != 'signMsg' && $v != '' && !is_array($v)) {
                $buff .= $k . '={' . urlencode($v, 'utf-8') . '}&';
            }
        }

        $buff = trim($buff, "&");
        return $buff;
    }

}